import url from "./url";
import util from "./util";

/**
 * 接口请求
 * options 请求信息
 * success 成功返回函数
 * fail 失败返回函数
 */
const appKey = url.urls.appKey // 用了做网关统计的 固定值
export const lkRequest = (options, success, fail) => {
  console.log(options)
  let header = {
    'Content-Type': 'application/x-www-form-urlencoded',
      appkey: appKey
  }
  let method = 'POST'
  if (options.contentType) {
    header['Content-Type'] = options.contentType
  }
  console.log('contentType', header['Content-Type']);
  if (options.method) {
    method = options.method
  }
  let params = {}
  if (options.params) {
    params = options.params
  }
   wx.request({
     header: header,
     method: method,
     url: options.url,
     dataType: 'json',
     data: params,
     success: success,
     fail: fail
   })
}

export const lkUploadFile = (options, success, fail) =>{
    let header ={appkey: appKey}
    if(options.header){
        header = Object.assign({appkey: appKey},options.header)
    }
    if (options.contentType) {
        header['Content-Type'] = options.contentType
    }
    wx.uploadFile({
        header:header,
        url: options.url,
        filePath: options.filePath,
        name: options.name,
        formData: options.formData,
        success:success,
        fail:fail
    })
}
//
// module.exports = {
//   lkRequest: lkRequest
// }
